﻿Namespace ControlLibrary

    Public Class dbiWSFReport

#Region "**Classes**"
        ''' <summary>Event Args for dbiList Node events.</summary>
        Public Class reportNodeEventArgs
            Inherits System.EventArgs
            Private l_NodeClicked As Dbi.WinControl.dbiNodeItem
            Private l_NodeTagObject As Object
            Private l_ReportName As String
            ''' <summary>The dbiNodeItem that triggered the event.</summary>
            Public Property NodeClicked() As Dbi.WinControl.dbiNodeItem
                Get
                    Return l_NodeClicked
                End Get
                Set(ByVal value As Dbi.WinControl.dbiNodeItem)
                    l_NodeClicked = value
                End Set
            End Property

            ''' <summary>The dbiWSF Object or other tagged object on the node.</summary>
            Public Property NodeTagObject() As Object
                Get
                    Return l_NodeTagObject
                End Get
                Set(ByVal value As Object)
                    l_NodeTagObject = value
                End Set
            End Property

            ''' <summary>The name of the report that triggered the event.</summary>
            ''' <remarks>This property is used because the report handler is generic and this
            ''' gives the developer an indicator as to what to do with the object being passed
            ''' in the NodeTagObject.</remarks>
            Public Property ReportName() As String
                Get
                    Return l_ReportName
                End Get
                Set(ByVal value As String)
                    l_ReportName = value
                End Set
            End Property

        End Class
#End Region

#Region "**Global Variables**"
        Private ReportName As String
#End Region

#Region "**Public Events**"
        ''' <summary>
        ''' Fires if a report node is double clicked.
        ''' </summary>
        ''' <param name="sender">Object</param>
        ''' <param name="e">reportNodeEventArgs for that node.</param>
        ''' <remarks>This event can be used for drilling down into the report.</remarks>
        Public Event reportLineDblClick(ByVal sender As Object, ByVal e As reportNodeEventArgs)
#End Region

#Region "**dbiWSFReport Methods**"
        ''' <summary>Loads and displays a dbiWSFReportObject in the dbiList1 control.</summary>
        Public Sub loadReport(ByVal reportObject As dbiWSF.UserInterface.dbiWSFReporting.dbiWSFReportObject)

            ReportName = reportObject.reportName
            Me.dbiLableTitle.Text = reportObject.ReportTitle
            Me.dbiLableCriteria.Text = reportObject.Criteria
            Me.dbiLabelDateRange.Text = reportObject.DateRange
            Me.DbiList1.ListType = reportObject.ReportListType
            Me.DbiList1.BodyIndent = reportObject.BodyIndent
            Me.DbiList1.PrintPageTitleText = reportObject.ReportTitle

            If reportObject.Criteria Is Nothing Then

                Me.DbiList1.PrintPageSubTitleText = reportObject.DateRange
                Me.dbiLableCriteria.Visible = False
                Me.dbiLableCriteria.Top = Me.dbiLabelDateRange.Top

            Else

                Me.DbiList1.PrintPageSubTitleText = reportObject.Criteria & " ... " & reportObject.DateRange
                Me.dbiLableCriteria.Visible = True
                Me.dbiLableCriteria.Top = Me.dbiLabelDateRange.Top + Me.dbiLabelDateRange.Height + 10

            End If

            'Populate the columns in the list
            Me.DbiList1.Columns.Clear()
            Dim column2Add As Dbi.WinControl.dbiColumnItem
            For Each column2Add In reportObject.ReportColumns
                Me.DbiList1.Columns.Add(column2Add)
            Next

            'Set the column delimiter
            Me.DbiList1.BreakChar = reportObject.ColumnDelimiter

            'add the nodes to the dbiList control
            Me.DbiList1.Items.Clear()
            Dim reportLine2Add As Dbi.WinControl.dbiNodeItem

            For Each reportLine2Add In reportObject.ReportLines
                Me.DbiList1.Items.Add(reportLine2Add)
                If reportLine2Add.Body.Length > 0 Then
                    Me.DbiList1.ItemHeightType = Dbi.WinControl.enumItemHeightType.Variable
                    Me.DbiList1.AutoSetNodeHeight(reportLine2Add)
                End If
            Next

            Me.DbiList1.Refresh()

        End Sub
#End Region

#Region "**dbiList Event Methods**"
        Private Sub DbiList1_NodeDoubleClick(ByVal sender As Object, ByVal e As Dbi.WinControl.NodeDoubleClickEventArgs) Handles DbiList1.NodeDoubleClick
            Dim eventArgs As New reportNodeEventArgs

            eventArgs.NodeClicked = e.Item
            eventArgs.NodeTagObject = e.Item.Tag
            eventArgs.ReportName = Me.ReportName
            RaiseEvent reportLineDblClick(Me, eventArgs)

        End Sub
#End Region

    End Class
End Namespace
